﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame4
{
    class Player_StopState : State
    {
        private static Player_StopState instance;

        private Player_StopState()
        {
            base.Name = "StopState";
        }

        public override void enter(AIObject aiObject)
        {
            //Console.WriteLine("<Player_StopState> enter");
            AIPlayer aiPlayer = (AIPlayer)aiObject;
            Player player = (Player)aiPlayer.Player;

            if (player.IdAnimation == "move_left")
                player.changeAnimation("left");
            if (player.IdAnimation == "move_right")
                player.changeAnimation("right");
            if (player.IdAnimation == "move_down")
                player.changeAnimation("front");
            if (player.IdAnimation == "move_up")
                player.changeAnimation("back");

        }

        public static Player_StopState getInstance()
        {
            if (instance == null)
                instance = new Player_StopState();
            return instance;
        }

        public override void execute(AIObject aiObject)
        {
            //Console.WriteLine("<Player_StopState> execute");
            AIPlayer aiPlayer = (AIPlayer)aiObject;
            Player player = (Player)aiPlayer.Player;

            if (player.ReloadTime > 0)
                player.ReloadTime -= player.Level;
            else
                player.Attack = true;
            /*
            if (aiPlayer.Player.Movement != null)
            {
                EventEmitter.getInstance().registerMessage(0, aiPlayer.Id, aiPlayer.Id, Message.MessageType.msg_move);
            }*/
        }

        public override void exit(AIObject aiObject)
        {
            //Console.WriteLine("<Enemy_StopState> exit");
            AIPlayer aiPlayer = (AIPlayer)aiObject;
        }

        public override Boolean onMessage(AIObject aiObject, Message message)
        {
            //Console.WriteLine("<Enemy_StopState> onMessage " + message.Type);
            Boolean correct = false;
            switch (message.Type)
            {
                case Message.MessageType.msg_move:
                    {
                        aiObject.StateMachine.changeState(Player_MoveState.getInstance());
                        correct = true;
                        break;
                    }
                case Message.MessageType.msg_newShoot:
                    {
                        AIPlayer aiPlayer = (AIPlayer)aiObject;
                        aiPlayer.Player.Attack = true;
                        correct = true;
                        break;
                    }
                case Message.MessageType.msg_disableBlinking:
                    {
                        AIPlayer aiPlayer = (AIPlayer)aiObject;
                        Player player = (Player)aiPlayer.Player;
                        player.Blinking = false;
                        correct = true;
                        break;
                    }
                case Message.MessageType.msg_attacked:
                    {
                        aiObject.StateMachine.changeState(Player_DestroyState.getInstance());
                        correct = true;
                        break;
                    }
            }
            return correct;
        }
    }
}
